package cn.kshost.zqyg.manager.controller;

import cn.kshost.zqyg.manager.service.BrandService;
import cn.kshost.zqyg.model.entity.product.Brand;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import cn.kshsot.zqyg.common.log.Log;
import cn.kshsot.zqyg.common.log.enums.OperatorType;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("/admin/product/brand")
public class BrandController {

    @Autowired
    BrandService brandService;

    @Operation(summary = "分页查询")
    @GetMapping("/{pageNum}/{pageSize}")
    public Result<PageInfo<Brand>> getBrandList(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
        PageInfo<Brand>  pageInfo = brandService.findByPage(pageNum,pageSize);
       return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    @Log(title = "品牌列表",operatorType = OperatorType.MANAGE,businessType = 1)
    @Operation(summary = "新增品牌")
    @PostMapping("/addBrand")
    public Result addBrand(@RequestBody Brand brand) {
        brandService.addBrand(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "修改品牌")
    @PutMapping("/modifyBrand")
    public Result modifyBrand(@RequestBody Brand brand) {
        brandService.modifyBrand(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除品牌")
    @DeleteMapping("/deleteBrand")
    public Result deleteBrand(@RequestBody Brand brand) {
        brandService.deleteBrand(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询所有品牌")
    @GetMapping("/getAllBrandList")
    public Result<List<Brand>> getAllBrandList() {
      List<Brand> brands =   brandService.getAllBrandList();
      return Result.build(brands, ResultCodeEnum.SUCCESS);
    }
}
